<!DOCTYPE html>
<html>
<head>
    <base href="/">
    <title>Login</title>
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all"/>
    <link rel="stylesheet" href="layui/css/layui.css">
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery.min.js"></script>
    <!-- Custom Theme files -->
    <!--theme-style-->
    <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
    <!--//theme-style-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="keywords" content="New Store Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design"/>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);

    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    <!--fonts-->
    <!--<link href='http://fonts.useso.com/css?family=Lato:100,300,400,700,900' rel='stylesheet' type='text/css'>-->
    <!--<link href='http://fonts.useso.com/css?family=Roboto:400,100,300,500,700,900' rel='stylesheet' type='text/css'>&lt;!&ndash;//fonts&ndash;&gt;-->
    <!-- start menu -->
    <link href="css/memenu.css" rel="stylesheet" type="text/css" media="all"/>
    <script type="text/javascript" src="js/memenu.js"></script>
    <script>$(document).ready(function () {
        $(".memenu").memenu();
    });</script>
    <script src="js/simpleCart.min.js"></script>
</head>
<body>
<!--header-->
<div class="header">
    <div class="header-top">
        <div class="container">
            <div class="search">
                <form action="shopping/goods" style="display: flex; gap: 8px;">
                    <input type="text" placeholder="Search" name="keywords">
                    <button type="button" name="searchbtn" class="layui-btn layui-btn-sm layui-btn-primary" >搜索</button>
                </form>
            </div>
            <div class="header-left">
                <ul>

                    <li>
                    </li>

                </ul>
                <div class="cart box_1">
                    <a href="shopping/cart">
                        <h3>
                            <div class="total">

                            </div>
                            <img src="images/cart.png" alt=""/></h3>
                    </a>
                    <p><a href="javascript:" class="simpleCart_empty">Login to view shopping cart</a></p>

                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
    <div class="container">
        <div class="head-top">
            <div class="logo">
                <a href="shopping/index"><img src="images/logo.png" alt=""></a>
            </div>
            <div class=" h_menu4">
                <ul class="memenu skyblue">
                    <li class="active grid"><a class="color8" href="shopping/index">Home</a></li>
                    <li><a class="color1" href="shopping/goods">Shop</a>
                    </li>
                </ul>
            </div>

            <div class="clearfix"></div>
        </div>
    </div>

</div>


<!--content-->
<div class="container">
    <div class="account">
        <h1>Account</h1>
        <div class="account-pass">
            <div class="col-md-8 account-top">
                <form>

                    <div>
                        <span>账户</span>
                        <input type="text" name="name">
                    </div>
                    <div>
                        <span>密码</span>
                        <input type="password" name="password">
                    </div>
                    <input type="button" value="Login" class="loginbtn layui-btn layui-btn-sm layui-btn-danger">
                </form>
            </div>
            <div class="col-md-4 left-account ">
                <a href="shopping/register"><img class="img-responsive " src="images/s1.jpg" alt="" style="width: 270px;height: 400px"></a>
                <div class="five">
                    <h2>25% </h2><span>discount</span>
                </div>
                <a href="shopping/register" class="create" style="width: 270px">Create an account</a>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>

</div>


<!--//content-->
<div class="footer">
    <div class="footer-class">
        <p><a>祝您购物愉快♥</a></p>
    </div>
</div>

<script src="layui/layui.all.js"></script>
<script>
    const $ = layui.$;
    const layer = layui.layer;

    $(".loginbtn").click(function () {
        //验证数据
        let name = $("[name='name']").val();
        console.log(name);
        let password = $("[name='password']").val();
        let reg = /^[a-zA-Z0-9]{6,16}$/;
        if (reg.test(password)) {
            $.ajax({
                //登陆操作
                url: 'shopping/dologin',
                data: {name: name, password: password},
                success: function (data) {
                    if (data === "success") {
                        layer.msg("登陆成功", {icon: 6});
                        setTimeout(function () {
                            location.href = "shopping/index";
                            // location.href = document.referrer || history.back();
                            // location.href = document.referrer || history.back();
                        }, 1200)
                    } else if (data === "notexist") {
                        layer.msg("账户不存在或密码错误");

                    } else if (data === "passerror") {
                        layer.msg("用户名或密码错误");

                    } else {
                        layer.msg("登陆失败系统异常");
                    }
                }
            })
        } else {
            layer.msg("密码长度错误");
        }
    });

    function easyCart() {
        $.ajax({
            url: "cart/list",
            data: {},
            async: false,
            success: function (cart) {
                let sumprice=0;
                let i=0;
                for (i = 0; i < cart.length; i++) {
                    sumprice+=(cart[i].number*cart[i].goods.price);
                }
                sumprice=Math.ceil(sumprice * 100) / 100;
                $(".total").html("<span>￥ &nbsp;&nbsp; "+sumprice+"</span>(<span>"+i+"</span>items)");
            }
        });
    }
    easyCart();



    $("[name='searchbtn']").click(function () {
        let searchtext=$("input[name='keywords']").val();
        location.href="shopping/goods?keywords="+searchtext;
    });

</script>

</body>
</html>
			